package compiler.nonterminals;

import compiler.HowlToken;
import compiler.HowlType;
import compiler.TokenReader;
import compiler.exceptions.HowlParserException;
import compiler.terminals.DataProvider;
import compiler.terminals.FeedName;
import compiler.terminals.Geolocation;

/**
 * This class represents register statements, as in:
 * 
 * register FeedName DataProvider
 * 
 * @author Sarah Mount <s.mount@wlv.ac.uk>
 * @version 16 Dec 2009
 * @see compiler.terminals.FeedName
 * @see compiler.terminals.DataProvider
 * @see compiler.terminals.Geolocation
 */
public class RegisterStmt extends HowlToken {

	private FeedName feedname;
	private DataProvider dataProvider;
	private Geolocation geolocation;

	public RegisterStmt(TokenReader tokenReader) {
		super(tokenReader);
	}

	@Override
	public String codeGenerate() {
		return "INSERT INTO " + this.feedname.codeGenerate() + " ("
				+ this.dataProvider.codeGenerate() + ");";
	}

	@Override
	public HowlToken parse() throws HowlParserException {
		String command = this.tokenReader.consumeToken();
		if (!"register".equals(command))
			throw new HowlParserException(this.tokenReader.getStatement(),
					this.tokenReader.getCharNo());
		this.feedname = (FeedName) new FeedName(this.tokenReader).parse();
		this.dataProvider = (DataProvider) new DataProvider(this.tokenReader)
				.parse();
		this.geolocation = (Geolocation) new Geolocation(this.tokenReader)
				.parse();
		return this;
	}

	@Override
	public String toString() {
		return "register " + this.feedname.toString() + " "
				+ this.dataProvider.toString() + " "
				+ this.geolocation.toString() + ";";
	}

	/**
	 * @return the feedname
	 */
	public FeedName getFeedname() {
		return feedname;
	}

	/**
	 * @param feedname the feedname to set
	 */
	public void setFeedname(FeedName feedname) {
		this.feedname = feedname;
	}

	/**
	 * @return the dataProvider
	 */
	public DataProvider getDataProvider() {
		return dataProvider;
	}

	/**
	 * @param dataProvider the dataProvider to set
	 */
	public void setDataProvider(DataProvider dataProvider) {
		this.dataProvider = dataProvider;
	}

	/**
	 * @return the geolocation
	 */
	public Geolocation getGeolocation() {
		return geolocation;
	}

	/**
	 * @param geolocation the geolocation to set
	 */
	public void setGeolocation(Geolocation geolocation) {
		this.geolocation = geolocation;
	}


}
